package com.yiba.vpn.utils;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;

/**
 * Created by Administrator on 2017/11/16 0016.
 */

public class BufferUtil {
    public static ByteBuffer getByteBuffer(String str) {
        return ByteBuffer.wrap(str.getBytes());
    }

    public static String getString(ByteBuffer buffer) {
        try {
            return Charset.forName("UTF-8").newDecoder().decode(buffer.asReadOnlyBuffer()).toString();
        } catch (Exception ex) {
            ex.printStackTrace();
            return "error";
        }
    }

}
